home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 13908 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.7 KB  |  45 lines

  1. Newsgroups: comp.lang.c
  2. Path: netcom.com!bnelson
  3. From: bnelson@netcom.com (Bob Nelson)
  4. Subject: Re: How to use assert( )
  5. Message-ID: <bnelsonDpn06z.CFq@netcom.com>
  6. Organization: a computer running Linux
  7. X-Newsreader: TIN [version 1.2 PL2]
  8. References: <4kc3k7$dur@orion.cybercom.net> <smryanDpKxLz.39v@netcom.com>
  9. Date: Wed, 10 Apr 1996 08:13:46 GMT
  10. Sender: bnelson@netcom17.netcom.com
  11.  
  12. On Tue, 9 Apr 1996 05:22:47 GMT, @#$%!?! wrote:
  13. >> #include <assert.h>
  14. >> assert(some_expression_which_must_be_true);
  15. >> as in 
  16. >> assert(f=fopen("name","r"));
  17.  
  18. This particular usage example has an obvious drawback if 'f' is used
  19. later in the program (as is likely) and NDEBUG is defined.
  20.  
  21. >> If the expression is false, the program is aborted. On a Unix system, it
  22. >> will print the file name, line number, and the failed expression to stderr.
  23.  
  24. Why limit the explanation of its behavior in terms of one particular
  25. platform in a newsgroup devoted to Standard C? In the spirit of system
  26. independence, please permit this abridged quote from the ISO document
  27. (7.2.1.1):
  28.  
  29. "When it is executed, if _expression_ is false [...] the assert macro
  30. writes information about the particular call that failed [...] on the
  31. standard error file in an implementation-defined format."
  32.  
  33. A footnote (97) adds that the message may be:
  34. "Assertion failed: _expression_, file _xyz_, line nnn"
  35.  
  36. Aside to Steve Summit -- might a brief foray into the proper use of
  37. the wondrous assert macro be worthy of inclusion in the FAQ?
  38.  
  39. -- 
  40. =============================================================================
  41.           Bob Nelson: Dallas, Texas, U.S.A.  -  bnelson@netcom.com
  42.       Linux for fun, M$ for $$$...and the NFL for what really counts!
  43. =============================================================================
  44.  
  45.